Method for operating an e-purse

ABSTRACT

The invention discloses a method for operating an e-purse, relating to the information security field. The method includes that a CPU card enters into a contactless induction area of a terminal, is powered up and initialized, receives an operation initializing instruction from the terminal, reads and stores data comprising transaction amount in the operation initializing instruction, and performs the related operation. The operation initializing instruction is a complex loading initializing instruction or a purchase initializing instruction. The data comprises transaction amount.

FIELD OF THE INVENTION

The invention relates to the information security field, in particular to a method for operating an e-purse in a CPU card.

BACKGROUND OF THE INVENTION

CPU card has a microprocessor which functions as a micro processor, inside of its chip and includes a central processor unit (CPU), a read-only memory (ROM), a random access memory (RAM) and an electrically erasable programmable read-only memory (EEPROM), and thus boasts of high-volume, higher security, off-line job and multi-function development.

The CPU card improves security by applying a powerful and stable security controller, and the internal and external authentication system particular to it and excluded authentication system flagged by Banking IC card specification ensure validity and security of a transaction, and firewall function of the CPU card guarantees security and independence of different applications in one card, and the high-volume storage space of the CPU card meets requirement of storage of more customer information generated by predictable large amount expenditure applications.

In the prior art, e-purse in a CPU card can perform basic transaction functions such as general loading, purchasing, cash withdrawing, and overdraw limit updating. However, for a special application, for example promotion on tier discounts for different loading amounts in those member cards of shopping mall, super market, restaurant, gymnasium and the like, the general loading and purchasing function of the e-purse in prior art is deficient.

SUMMARY OF THE INVENTION

In order to solve the problem in the prior art, the invention provides a method for operating an e-purse.

A method for operating an e-purse, comprising:

-   -   entering into a contactless induction area of a terminal, being         powered up and initialized by a CPU card, receiving an operation         initializing instruction, which is a complex-complex loading         initializing instruction or a purchase initializing instruction         sent by the terminal, reading and storing data comprising a         transaction amount, included in the operation initializing         instruction;         in case that the operation initializing instruction is a         complex-loading initializing instruction, performing a         complex-loading initializing operation by the CPU card,         receiving an instruction for updating a complex application         specific file sent by the terminal, retrieving the complex         application specific file, writing predetermined data into the         storage space of the complex application specific file to         replace what is previously in the storage space, receiving the         complex-complex loading instruction sent by the terminal,         reading and storing data in the complex-complex loading         instruction, computing the transaction amount and data in the         complex application specific file according to predetermined         algorithm to obtain a new amount and adding the new amount to         balance of the e-purse to obtain a new balance;         in case that the operation initializing instruction is a         purchase initializing instruction, computing the transaction         amount and value in related record of the complex application         specific file according to predetermined algorithm to obtain a         new amount by the CPU card, reading balance of the e-purse,         determining whether the new amount is larger than balance of the         e-purse plus the overdraft limit of the e-purse, if yes,         returning a message of inadequate balance in the e-purse to the         terminal and ending the operation by the CPU card; if no,         generating a pseudo random umber and a process key, sending a         message in response to the purchase initializing instruction to         the terminal, receiving a purchase instruction sent by the         terminal, reading and storing data in the purchase instruction,         deducting the new amount from balance of the e-purse to obtain a         newer amount and returning a message in response to the purchase         instruction to the terminal.

Advantages:

The invention discloses a method for operating an e-purse, which makes the whole transaction safer, prevents the complex application specific file in a CPU card from being modified invalidly, simplifies the tier discounts by setting the complex application specific file in case of loading, and reduces cost on management.

BRIEF DESCRIPTIONS OF THE DRAWINGS

FIG. 1 is a flow chart of a method for complex-loading an e-purse provided in Embodiment 1;

FIG. 2 is a detailed flow chart of a method for complex-loading an e-purse provided in Embodiment 1;

FIG. 3 is a detailed flow chart of a method for purchase with an e-purse provided in Embodiment 1;

FIG. 4 is a flow chart of a method for purchase with an e-purse provided in Embodiment 2; and

FIG. 5 is a detailed flow chart of a method for purchase with an e-purse provided in Embodiment 2.

DETAILED DESCRIPTIONS OF THE EMBODIMENTS

For making purpose, solution and advantage of the invention more explicit, a detailed description will be given of embodiments of the invention in accompany with the drawings.

Embodiment 1

For simplifying the tier discounts preference, a complex application specific file is required to be set in case of complex loading. The embodiment provides a method for complex-loading an e-purse, as shown in FIG. 1, including steps as follows.

Step S1, CPU card enters into a contactless induction area of a terminal, is powered up and initialized.

Step S2, the CPU card receives a complex loading initializing instruction sent by the terminal, reads and stores data including transaction amount, in the complex loading initializing instruction and executes the complex loading initializing operation.

Step S3, the CPU card receives an instruction for updating the complex application specific file sent by the terminal and retrieves the complex application specific file.

Step S4, write predetermined data to the storage space of the complex application specific file and replace what is previously in the storage space.

Step S5, receive the complex loading instruction sent by the terminal, read and store data in the complex loading instruction.

Step S6, compute the transaction amount and data in the complex application specific file with predetermined algorithm to obtain a new amount, add the new amount to balance of the e-purse to obtain a new balance, and end the complex loading.

Embodiments are provided below for detailed description of the method of the invention.

Embodiment 1

The embodiment provides a method for complex-loading an e-purse, for example an e-purse in a CPU card in the embodiment. Besides basic transaction functions of a common e-purse, the e-purse in a CPU card boasts of all transaction functions of a complex application e-purse along with the complex-loading function, and the complex-loading of the e-purse in a CPU card is executed at a CPU terminal. When complex-loading of the e-purse in a CPU card, it computes a transaction amount and a value specially defined in the complex application specific file with predetermined algorithm to obtain a new amount and adds the new amount to balance of the e-purse, and correspondingly the payment is executed with the balance in case of paying.

As shown in FIG. 2, a method for complex loading of an e-purse in a CPU card includes steps as follows.

Step 101, a CPU card enters into a contactless induction area of a terminal, is powered up and initialized.

Step 102, receive a complex-loading initializing instruction INITIALIZE FOR CAPP LOAD sent by the terminal, read and store data in the instruction.

In the embodiment, the complex-loading initializing instruction INITIALIZE FOR CAPP LOAD is used for initializing the complex-loading transaction, and message in the instruction INITIALIZE FOR CAPP LOAD is comprised of an instruction header and an instruction body, which are respectively (CLA INS+P1+P2) and (Lc+Data+Le).

CLA+INS+P1+P2 refer to the instruction header and Lc+Data+Le refer to the instruction body. The instruction header includes codes of the instruction, of which CLA refers to type of the instruction, INS to codes of the instruction, P1 and P2 to parameters of the instruction respectively. Of the instruction body, Lc refers to size of the data in Data field, Data to data in the instruction INITIALIZE FOR CAPP LOAD and Le to the maximum number of bytes in APDU data field.

The data in Data field of the instruction INITIALIZE FOR CAPP LOAD includes a key indexing number, a transaction amount and a terminal number in the embodiment.

Specifically, the received instruction INITIALIZE FOR CAPP LOAD in the embodiment is 80 50 06 02 0B 02 00 00 03 E8 00 00 00 00 00 01 10, of which 80 refers to CLA, 50 to INS, 06 to P1 which is defined as a complex-loading initializing flag, 02 to P2 which is defined as an e-purse flag, 0B to Lc, 02 to the key indexing number in Data field, 00 00 03 E8 to the transaction amount in Data field, 00 00 00 00 00 01 to the terminal number in Data field and 10 to Le.

Step 103, check whether the CPU card itself supports the key indexing number included in the instruction INITIALIZE FOR CAPP LOAD, if no, Step 104 is executed; if yes, Step 105 is executed.

Step 104, return a status code 0x9403 to the terminal and end the complex loading initializing operation.

Step 105, generate a four-byte pseudo-random number and a process key.

The generating process key in the embodiment includes steps of linking the pseudo random number, serial number of online transaction of the e-purse and 8000 together, encrypting the linked data with a loading key DLK to obtain encrypted data, that is the process key.

Step 106, compute a first message authenticating code MAC1 with the process key.

The computing a first message authenticating code MAC1 with the process key includes steps of linking the balance, transaction amount, transaction type ID and terminal number of the e-purse together before the transaction, encrypting the linked data with the process key. The first four bytes of the encrypted data are the first message authenticating code MAC1.

Step 107, return a message in response to the instruction INITIALIZE FOR CAPP LOAD to the terminal.

The message in response to the instruction INITIALIZE FOR CAPP LOAD is comprised of Data+sw1+sw2, in case of a successful execution of the instruction INITIALIZE FOR CAPP LOAD, both status codes sw1 and sw2 in the response message are 9000 and data in Data field of the response message includes balance of CPU c-purse before the transaction, serial number of online transaction of the CPU e-purse, version number of the key, algorithm identification (ID), pseudo random number and MAC1;

or in case of a failed execution of the instruction INITIALIZE FOR CAPP LOAD, both status codes sw1 and sw2 in the response message are not 9000 and there is not a DATA field.

Specifically, the message in response to the instruction INITIALIZE FOR CAPP LOAD is 00 00 00 00 00 01 02 03 01 02 03 04 00 01 B10A 90 00.

Step 108, receive an instruction UPDATE CAPP DATA CACHE for updating the complex application specific file sent by the terminal.

The instruction UPDATE CAPP DATA CACHE is used for updating data in the complex application specific file. The complex application specific file is comprised of a file header and a file body. The file header includes a two-byte FILE_ID, one-byte FILE TYPE, two-byte FILE SIZE, one-byte AC1, one-byte AC2 and two-byte RFU. FILE TYPE 00 indicates a binary file, 01 a fix-sized record file, 02 a changeable-sized record file, 03 a recycle file and 05 a key file. Correspondingly, File Size for a binary file represents size of the file, File Size for a fix-sized record file refers to number and size of records, File Size for a changeable-sized record file to number and maximum size of records, File Size for a recycle file to number and size of records, and File Size for a key file to number and size of records. AC1 refers to a file reading privilege and AC2 to a file writing privilege. What is in the file body is data in the complex application specific file.

Specifically, the complex application specific file is a binary file, and so FILE TYPE is 00, FILE SIZE refers to size of the file which is 000B and content in the file body is empty.

Further, message of the instruction UPDATE CAPP DATA CACHE is comprised of CLA+INS+P1+P2 Lc+Data and in the embodiment, the instruction UPDATE CAPP DATA CACHE is 80 D6 92 B1 04 00 01 20 00, of which 80 refers to CLA, D6 to INS, 92 to P1, B to P2, 04 to Lc and 00 01 20 00 to Data.

Data in Data field of the instruction UPDATE CAPP DATA CACHE is new data to be written to the complex application specific file. Because special application of the complex application specific file may be defined by a card distributor, so be data in Data field. Specifically, in case that the complex application specific file is defined as a rate file, data in Data field is value of the rate, such as 120%.

In case of a defined rate value of 120%, data in the instruction UPDATE CAPP DATA CACHE may be not 120%, but 83.3 or 20%.

Or data in the instruction UPDATE CAPP DATA CACHE may not include a rate value, but generate a rate value with a transaction amount after determination of the transaction amount included in the complex loading initializing instruction by the CPU card, and the generated rate value is written to the complex application specific file.

For example, in case of a transaction amount of RMB800 yuan in the complex loading initializing instruction, less than the predetermined lower limit RMB2000 yuan, a rate value of 90% or 111.1% or 11.1% or RMB100 yuan is generated; in case of a transaction amount of RMB5000 yuan in the complex loading initializing instruction, between the predetermined lower limit RMB2000 yuan and the upper limit RMB6000 yuan, a rate value of 80% or 125% or 25% or RMB600 yuan is generated; in case of a transaction amount of RMB8000 yuan in the complex loading initializing instruction, more than the predetermined lower limit, a value of 75%, or 133%, or 33%, or RMB2000 yuan and etc. is generated.

Step 109, determine whether there is an SFI (short file identifier) field in the received instruction UPDATE CAPP DATA CACHE, if yes, Step 110 is executed; if no, Step 111 is executed.

The determining whether there is an SFI field in the instruction UPDATE CAPP DATA CACHE includes steps of determining whether the higher three bits of the instruction UPDATE CAPP DATA CACHE are 100, if yes, there is an SFI field and the lower five bits refer to value of the SFI field; or if no, there is not an SFI field.

Specifically, P1 of the instruction UPDATE CAPP DATA CACHE is 92, which indicates that the higher three bits of P1 are 100 and there is an SFI field.

Step 110, retrieve whether there is a file under the current application of the CPU card with a same SFI as the SFI in the instruction UPDATE CAPP DATA CACHE, if no, Step 111 is executed; if yes, Step 112 is executed.

Step 111, return a status code 0x6A82 to the terminal and end the operation.

Step 112, take the file retrieved at Step 110 as the complex application specific file and check whether size of Data field in the instruction UPDATE CAPP DATA CACHE is larger than size of the complex application specific file, if yes, Step 113 is executed; or if no, Step 114 is executed.

Because the complex application specific file is a binary file, size of it is value of FILE SIZE. Step 112 specifically is determining whether value of Lc field in the instruction UPDATE CAPP DATA CACHE is bigger than the value of FILE SIZE in the complex application specific file. The value of Lc field in the instruction UPDATE CAPP DATA CACHE is 04 and value of FILE SIZE is 000B, and therefore size of Data field in the instruction UPDATE CAPP DATA CACHE is not larger than that of the complex application specific file.

Step 113, return a status code 0x6A84 to the terminal and end the operation.

Step 114, write data in Data field of the instruction UPDATE CAPP DATA CACHE to the complex application specific file and replace what is previously in it.

It includes steps of writing a rate value of 120% to the complex application specific file and replacing what is previously in it.

Because the complex application specific file is an empty file, the step is writing 00 01 20 00 in Data field of the instruction UPDATE CAPP DATA CACHE to the complex application specific file.

In case of a rate value of 83% in the instruction UPDATE CAPP DATA CACHE, the step is writing 83.3% to the complex application specific file; or in case of a rate value of 20% in the instruction UPDATE CAPP DATA CACHE, the step is writing 20% into the complex application specific file.

Or data in the instruction UPDATE CAPP DATA CACHE may not include a rate value, but generate a rate value with a transaction amount according to predetermined algorithm after determination of the transaction amount included in the complex loading initializing instruction by the CPU card, and then the generated rate value is written to the complex application specific file after determining whether size of the generated value is larger than size of the complex application specific file or not. For example, in case of a transaction amount of RMB800 yuan in the complex-loading initializing instruction, less than the predetermined lower limit RMB2000 yuan, a rate value of 90% or 111.1% or RMB100 yuan is generated and written to the complex application specific file; in case of a transaction amount of RMB5000 yuan in the complex-loading initializing instruction, between the predetermined lower limit RMB2000 yuan and the upper limit RMB6000 yuan, a rate value of 80% or 125% or 25% or RMB600 yuan is generated and written to the complex application specific file; in case of a transaction amount of RMB8000 yuan in the complex-loading initializing instruction, bigger than the predetermined upper limit RMB6000 yuan, a rate value of 75% or 133% or 33% or RMB2000 yuan is generated and written to the complex application specific file.

Step 115, return a message in response to the instruction UPDATE CAPP DATA CACHE to the terminal.

The message in response to the instruction UPDATE CAPP DATA CACHE is comprised of sw1+sw2 and there is not a DATA field. In case of a successful execution of the instruction, the response message is 9000 while in case of a failed execution of the instruction, the response message is not 9000.

Step 116, receive the complex-loading instruction CREDIT FOR CAPP LOAD sent by the terminal, read and store data in Data field of the instruction.

The complex-loading instruction CREDIT FOR CAPP LOAD is used for complex loading the transaction, and message of the instruction CREDIT FOR CAPP LOAD is comprised of CLA+INS+P1+P2+Lc+Data+Le, of which data in Data field includes transaction date, transaction time and a second message authenticating code MAC2.

The received instruction CREDIT FOR CAPP LOAD is 80 52 00 00 0B 07 DA 06 08 0A 14 2D 00 01 A1 0B 08, of which 80 refers to CLA, 52 to INS, 00 to Pt, 00 to P2, 0B to Lc, 07 DA 06 08 to transaction date in Data field, 0A 14 2D to the transaction time in Data field, 00 01 A1 0B to MAC2 in Data field and 08 to Le.

Step 117, authenticate whether the second message authenticating code MAC2 is valid, if no, Step 118 is executed; or if yes, Step 119 is executed.

The authenticating whether MAC2 is valid includes steps of linking the transaction amount, transaction type id, terminal number, transaction date and time together, encrypting the linked data with the process key generated at step 105, and comparing the first four bytes of the encrypted data to MAC2 in Data field of the instruction CREDIT FOR CAPP LOAD, if a match is not found, MAC2 is invalid; or if a match is found, MAC2 is valid.

Step 118, return a status code 0x9302 to the terminal and prompt an invalid MAC2.

Step 119, add 1 to the serial number of online transaction of the e-purse, compute the transaction amount and value in the complex application specific file with a predetermined algorithm to obtain a new amount and add the new amount to balance of the e-purse.

The predetermined algorithm includes multiplex, division, addition, subtraction and various combinations of the four algorithms.

Further, value in the complex application specific file refers to a rate value, for example 120%, and in case of a transaction amount of RMB1000 yuan and a balance of RMB0 yuan in the e-purse, a new amount RMB1200 yuan is obtained by multiplexing the transaction amount RMB1000 yuan by the rate value of 120% recorded in the complex application specific file, and then a new balance RMB1200 yuan is obtained by adding the new amount RMB1200 yuan to the balance RMB0 yuan of the e-purse, and so the new balance RMB1200 yuan of the e-purse is bigger than the transaction amount RMB1000 yuan plus the balance RMB0 yuan of the e-purse.

In case of a rate value of 83.3% being written in the complex application specific file, if the transaction amount is RMB1000 yuan and balance of the e-purse is RMB0 yuan, a new amount RMB1200 yuan is obtained by dividing the transaction amount RMB1000 yuan by the rate value of 83.3%, and a new balance RMB1200 is obtained by adding the new amount RMB1200 yuan to the balance RMB0 yuan of the e-purse and the new balance RMB yuan of the e-purse is bigger than the transaction amount RMB1000 yuan plus the balance RMB0 yuan of the e-purse.

In case of a rate value of 20% being written in the complex application specific file, if the transaction amount is RMB1000 yuan and balance in the e-purse is RMB0 yuan, a new amount RMB1200 yuan is computed by transaction amount RMB1000 yuan* rate value of 20%+transaction amount RMB1000 yuan, and a new balance RMB1200 yuan is obtained by adding the new amount RMB1200 yuan to the balance RMB0 yuan of the e-purse and the new balance RMB1200 yuan of the e-purse is bigger than the transaction amount RMB1000 yuan plus the balance RMB0 yuan of the e-purse.

Or in case of a transaction amount RMB8000 yuan in the complex-loading initializing instruction, a rate value 75% or 133% or 33% or RMB2000 yuan is generated and written to the complex application specific file. For example, in case of a rate value of 75%, a new amount RMB10060 yuan is computed by dividing the transaction amount RMB8000 yuan by 75%, and a new balance RMB10060 yuan is computed by adding the new amount RMB10060 yuan to the balance RMB0 yuan of the e-purse and the new balance is bigger than the transaction amount RMB8000 yuan plus the balance RMB0 yuan of the e-purse. For another example, in case of a written rate value of 133%, a new amount RMB10060 yuan is computed by multiplexing the transaction amount RMB8000 yuan by the rate value of 133%, and a new balance of RMB10060 yuan is computed by adding the new amount RMB10060 yuan to the balance RMB0 yuan of the e-purse and the new balance is bigger than the transaction amount RMB8000 yuan plus the balance RMB0 yuan of the e-purse. For further example, in case of a written rate value of 33%, a new amount of RMB10060 yuan is obtained by the transaction amount RMB8000 yuan *the rate value 33%+the transaction amount of RMB8000 yuan, and a new balance of RMB10060 yuan of the e-purse is computed by adding the new amount RMB10060 yuan to the balance RMB0 yuan of the e-purse and the new balance is bigger than the transaction amount RMB8000 yuan plus the balance RMB0 yuan of the e-purse. For further example, in case of a written rate value of RMB2000 yuan, a new amount of RMB10000 yuan is computed by adding the transaction amount RMB8000 yuan to the rate value RMB2000 yuan, and a new balance RMB10000 yuan is computed by the new amount RMB10000 yuan plus the balance RMB0 yuan, and the new balance is larger than the transaction amount RMB8000 yuan plus the balance RMB0 yuan of the e-purse.

Step 120, update transaction details of the e-purse.

Specifically the step is linking serial number of online transaction of the e-purse, transaction amount, transaction type id, terminal number, transaction date and time together to form a record for updating the standard transaction details.

Step 121, compute a transaction authenticating code TAC.

The step includes sub-steps of performing XOR operation on the left and right 8 bytes of DTK, linking the after-transaction balance of e-purse, serial number of online transaction of the e-purse before adding 1, transaction amount, transaction type id, terminal number, transaction date and time together, and encrypting the linked data with the result from the XOR operation to obtain an encrypted data TAC.

Step 122, return a message in response to the instruction CREDIT FOR.CAPP LOAD to the terminal and end the complex loading operation.

The message in response to the instruction CREDIT FOR CAPP LOAD is comprised of data+sw1+sw2, and in case of a successful execution of the instruction CREDIT FOR CAPP LOAD, both the status codes sw1 and sw2 in the message in response to the instruction CREDIT FOR CAPP LOAD are 9000 and data in DATA field is TAC, or in case of a failed execution of the instruction CREDIT FOR CAPP LOAD, the status codes sw1 and sw2 in the message in response to the instruction CREDIT FOR CAPP LOAD are not 9000 and there is not a DATA field.

The message in response to the instruction CREDIT FOR CAPP LOAD is 00 05 D2 BC 90 00 in the embodiment.

In case that the complex application specific file is a record file, each record in the complex application specific file relates to an application. Specifically, File Type 01 flags the complex application specific file as a fix-sized record file, and File Size for the fix-sized record file are number and size of records.

Steps 108-116 for updating the complex application specific file may be replaced with steps as follows.

Step 108′, receive a record updating instruction UPDATE RECORD sent by the terminal.

The record updating instruction UPDATE RECORD is used for updating a record designated in the instruction and is applicable for both fix-sized and changeable-sized record file.

The message of the instruction UPDATE RECORD is comprised of CLA INS+P1+P2+Lc+Data, of which P1 and P2 are used for selecting a file and designating a record therefrom as record for the complex application specific file and Lc is size of Data field plus 4 bytes. Specifically the instruction UPDATE RECORD is comprised of 00 DC 03 04 08 00 01 20 00, of which 00 refers to CLA, DC to INS, 03 to P1, 04 to P2, 08 to Lc and 00 01 20 00 to Data.

What is in Data field of the instruction UPDATE RECORD is new data to be written to the complex application specific file, and special application of the complex application specific file may be defined by a card distributor, so be data in Data field. For example, the complex application specific file may be defined as a rate value file and thus data in Data field refers to a rate value, such as 120%.

Step 109′, determine whether there is an SFI field in the record updating instruction UPDATE RECORD, if yes, Step 110′ is executed; or if no, Step 111′ is executed.

The determining whether there is an SFI field in the record updating instruction UPDATE RECORD specifically includes determining whether all higher five bits of P2 in the instruction UPDATE RECORD are 0, if yes, there is an SFI field and the high five bits of P2 are value in SFI field; or if no, there is not an SFI field.

Step 110′, retrieve whether there is a file under the current application of the CPU card, with a same SFI as that SFI in the instruction UPDATE RECORD, if no, Step 111′ is executed; or if no, Step 112′ is executed.

Step 111′ return a status code 0x6A82 to the terminal and end the complex-loading operation.

Step 112′, take the file retrieved at Step 110′ as the complex application specific file and retrieve the record from the complex application specific file according to a designated record number in the instruction UPDATE RECORD, if no retrieved, Step 113′ is executed; or if retrieved, Step 114′ is executed.

Step 113′, return a status code 0x6A83 to the terminal and end the complex-loading operation.

Step 114′, check whether size of Data field in the instruction UPDATE RECORD is larger than size of the record retrieved at Step 112′, if yes, Step 115′ is executed; or if no, Step 116′ is executed.

Step 115′, return a status code 0x6A84 to the terminal and end the complex-loading operation.

Step 116′, write data in Data field of the instruction UPDATE RECORD to the retrieved record and replace what is previously in the record.

The step is writing a rate value of 120% into the record, and replacing what is previously in the record.

Step 117′, return a message in response to the instruction UPDATE RECORD to the terminal.

The message in response to the instruction UPDATE RECORD is comprised of sw1+sw2 and there is not a Data field. The message is 9000 in case of a successful execution of the instruction UPDATE RECORD, or not 9000 in case of a failed execution of the instruction UPDATE RECORD.

After the complex-loading operation by the above method, the e-purse in the CPU card can be used to purchase, as shown in FIG. 3, including purchase steps as follows.

Step 201, receive a purchase initializing instruction INITIALIZE FOR. PURCHASE sent by the terminal, read and store data in the instruction.

The purchase initializing instruction INITIALIZE FOR PURCHASE is used for initializing a purchase.

The message of the instruction INITIALIZE FOR PURCHASE is comprised of an instruction header and an instruction body, for example (CLA+INS+P1+P2)+(Lc+Data+Le).

CLA+INS+P1+P2 is instruction header and Lc+Data+Le is instruction body.

The instruction header refers to codes of the instruction, of which CLA represents type of the instruction, INS are codes of the instruction, P1 and P2 are parameters of the instruction. Of the instruction body, Lc refers to size of data in Data field, Data to data of the instruction INITIALIZE FOR PURCHASE and Le to maximum number of bytes in Data field of the expected answer APDU.

Data in the instruction INITIALIZE FOR PURCHASE includes a key indexing number, a transaction amount and a terminal number.

The received instruction INITIALIZE FOR PURCHASE is 80 50 01 02 0B 02 00 00 00 C8 00 00 00 00 00 01 0F, of which 80 refers to CLA, 50 to INS, 01 to P1, 02 to P2 which is defined as an e-purse flag, 0B to Lc, 02 to the key indexing number in Data field, 00 00 00 C8 to the transaction amount in Data field, 00 00 00 00 00 01 to the terminal number in Data field and 0F to Le.

Step 202, check whether the CPU card supports the key indexing number included in the instruction INITIALIZE FOR PURCHASE, if no, Step 203 is executed; or if yes, Step 204 is executed.

Step 203, return a status code 0x9403 to the terminal and end the purchase initializing operation.

Step 204, read balance of the e-purse and determine whether the transaction amount included in the instruction INITIALIZE FOR PURCHASE is bigger than the balance plus overdraft limit of the e-purse, if yes, Step 205 is executed; or if no, Step 206 is executed.

Step 205, return a status code 0x9401 to the terminal and end the purchase initializing operation.

Step 206, generate a pseudo random number and a process key.

The process key is used for purchase with a CPU e-purse or an M1 e-purse, which is obtained by permission of DPK.

Step 207, send a message in response to the instruction INITIALIZE FOR PURCHASE to the terminal.

The message in response to the instruction INITIALIZE FOR PURCHASE is comprised of Data+sw1+sw2. In case of a successful execution of the instruction, both the status codes sw1 and sw2 in the response message are 9000 and data in Data field of the response message includes balance of the e-purse, serial number of offline transaction of the CPU e-purse, overdraft limit of the CPU e-purse, version number of the key, algorithm id and pseudo random number; or in case of a failed execution, there are only the status codes sw1 and sw2 in the response message and values thereof are not 9000.

The message in response to the instruction INITIALIZE FOR PURCHASE, being returned to the terminal, is 00 00 4B 00 00 01 00 00 64 02 03 01 02 03 04 90 00.

Step 208, receive a purchase instruction DEBIT FOR PURCHASE sent by the terminal, read and store data thereof.

The instruction DEBIT FOR PURCHASE is used for purchase.

The message of the instruction DEBIT FOR PURCHASE is also comprised of CLA+INS+P1+P2+Lc+Data+Le and data in the instruction DEBIT FOR PURCHASE includes a terminal transaction serial number, transaction date, transaction time and a third message authenticating code MAC3.

The received instruction DEBIT FOR PURCHASE is 80 54 01 00 0F 00 00 00 01 7D A0 06 09 0F 27 13 01 0A D1 0C 08, of which 80 refers to CLA, 54 to INS, 01 to P1, 00 to P2, 0F to Lc, 00 00 00 01 to the terminal transaction serial number in Data field, 7D A0 06 09 to the transaction date in Data field, 0F 27 13 to transaction time in Data field, 01 0A D1 0C to MAC3 in Data field and 08 to Le.

Step 209, authenticate whether MAC3 included in the instruction DEBIT FOR PURCHASE is valid by the process key generated at Step 205, if no, Step 210 is executed; or if yes, Step 211 is executed.

The authenticating whether MAC3 included in the instruction DEBIT FOR PURCHASE is valid includes steps of linking the transaction amount, transaction type id, terminal number, transaction date and time of the terminal together, encrypting the linked data with a process key generated at Step 206, and comparing the first four bytes of the encrypted data to MAC3 included in the instruction DEBIT FOR PURCHASE, if a match is found, MAC3 is valid; or if no, MAC3 is invalid.

Step 210, return a status code 0x9302 to the terminal and end the operation.

Step 211, add 1 to serial number of offline transaction of the e-purse and deduct the addition from balance of the e-purse.

In case of a transaction amount of RMB200 yuan and a balance of RMB1200 yuan in the e-purse, a new balance of RMB1000 yuan is computed by deducting RMB200 yuan from the original balance RMB1200 yuan of the e-purse.

Step 212, update transaction details of the e-purse.

The transaction details of the e-purse, to be updated includes a transaction amount, a transaction type id, a terminal number, transaction date and time. The CPU card links the transaction amount, transaction type id, terminal number, transaction date and time together to form a record for updating.

Step 213, generate a fourth message authenticating code MAC4 and compute a transaction authenticating code TAC.

The generating a fourth message authenticating code MAC4 includes steps of encrypting the transaction amount with the process key generated at Step 206 and taking the first four bytes of the encrypted data as the fourth message authenticating code MAC4.

Computing TAC with the XOR operation result includes steps of performing an XOR operation on the left and right 8 bytes of DTK, linking the transaction amount, transaction type id, terminal number, transaction serial number of the terminal, terminal transaction date and time together, encrypting the linked data with the XOR operation result and taking the first four bytes of the encrypted data as TAC code.

Step 214, return a message in response to the instruction DEBIT FOR PURCHASE to the terminal and end the transaction.

The message in response to the instruction DEBIT FOR PURCHASE is comprised of data+sw1+sw2. In case of a successful execution of the instruction DEBIT FOR PURCHASE, both the status codes sw1 and sw2 in the response message are 9000 and data in Data field are TAC and MAC4, or in case of a failed execution, the status codes sw1 and sw2 are not 9000 and there is not a Data field.

The message in response to the instruction DEBIT FOR PURCHASE is 01 0D B1 09 00 02 EA B1 90 00.

The embodiment discloses a method for complex-loading of the e-purse inside a CPU card, which makes the complex-loading safer and prevents the complex application specific file in the CPU card from being modified invalidly. Also, the method simplifies the tier discount operation by writing new data to the complex application specific file, this is that a new discount rate based on a recharging amount is set during a recharging process, and it makes management easier. The discount a member has been given only relates to his or her recharging amount, and more recharging amount means more discounts, and therefore it reduced cost on management.

Embodiment 2

For simplifying the tier discount operation and automatically processing purchase amount, the embodiment of the invention discloses a method for purchase with an e-purse, as shown in FIG. 4, including steps as follows.

Step 401, a CPU card enters into a contactless induction area of a terminal, is powered up and initialized.

Step 402, the CPU card waits for receiving an instruction sent by the terminal.

Step 403, in case of receiving a purchase initializing instruction sent by the terminal, the CPU card reads and stores data thereof.

The data includes a transaction amount.

Step 404, the CPU card computes transaction amount and value in a related record in the complex application specific file with predetermined algorithm to obtain a new amount.

Step 405, the CPU card reads balance of the e-purse and determines whether the new amount is bigger than the balance plus overdraft limit of the e-purse, if yes, sends a message of inadequate balance in the e-purse to the terminal and ends the transaction; or if no, generates a pseudo random number and a process key and returns a message in response to the purchase initializing instruction to the terminal.

Step 406, receive a purchase instruction sent by the terminal, read and store data thereof.

Step 407, deduct the new amount from balance of the e-purse to obtain a new balance and return a message in response to the purchase instruction to the terminal.

The following is detailed description of Embodiment 2 provided in the invention.

Embodiment 3

The embodiment of the invention discloses a method for purchase with an e-purse. Besides all transaction functions provided by a complex application e-purse, the e-purse inside the CPU card further supports complex-loading and purchase. Complex-loading of the e-purse inside the CPU card is executed at the CPU terminal. For example the complex-loading is executed by adding transaction amount to balance of the e-purse and then in case of purchase, computing the transaction amount and value in a related record of the complex application specific file according to predetermined algorithm to obtain a new amount and deducting the new amount from balance of the e-purse to obtain a new balance.

As shown in FIG. 5, a method for purchase with an e-purse is implemented by following steps.

Step 501, the CPU card enters into a contactless induction area of a terminal, is powered up and initialized.

Step 502, the CPU card waits for receiving an instruction sent by the terminal, and Step 503 is executed in case of receiving a complex-loading initializing instruction INITIALIZE FOR CAPP LOAD or Step 526 is done in case of receiving a purchase initializing instruction.

Step 503, read and store data in the complex-loading initializing instruction

INITIALIZE FOR CAPP LOAD.

The complex-loading initializing instruction INITIALIZE FOR CAPP LOAD is used for initializing the complex loading, and message of the instruction is comprised of an instruction header and an instruction body, (CLA+INS+P1+P2)+(Lc+Data+Le). CLA+INS+P1+P2 are instruction header, specifically codes of the instruction, of which CLA is type of the instruction, INS are codes of the instruction, P1 and P2 are parameters of the instruction. Lc+Data+Le is the instruction body, of which Lc represents size of data in. Data of the instruction body, Data represents the data in the instruction INITIALIZE FOR CAPP LOAD and Le represents the number of maximum bytes of Data field of expected APDU.

Data in Data field of the instruction INITIALIZE FOR CAPP LOAD includes a key indexing number, a transaction amount and a terminal number.

Specifically, the received instruction INITIALIZE FOR CAPP LOAD is 80 50 06 02 0B 02 00 00 03 E8 00 00 00 00 00 01 10, of which 80 refers to CLA, 50 to INS, 06 to P1, which is defined as a complex-loading initializing flag, 02 to P2, which is defined as an e-purse id, 0B to Lc, 02 to the key indexing number of Data field, 00 00 03 E8 to the transaction amount in Data field, 00 00 00 00 00 01 to the terminal number in Data field and 10 to Le.

Step 504, check whether the CPU card supports the key indexing number included in the instruction INITIALIZE FOR CAPP LOAD, if no, Step 505 is executed; or if yes, Step 506 is done.

Step 505, send a status code 0x9403 to the terminal and end the complex loading initializing operation.

Step 506, generate a four-byte pseudo random number and a process key.

The method for generating the process key includes steps of linking the pseudo random number, the serial number of online transaction of the e-purse and 8000 together, encrypting the linked data with a loading sub-key DLK and taking the encrypted data as the process key.

Step 507, compute the process key to obtain a first message authenticating code MAC1.

The computing the process key to obtain a first message authenticating code MAC1 includes steps of linking balance of the e-purse before the transaction, transaction amount, transaction type id of the e-purse and the terminal number together, encrypting the linked data with the process key and taking the first four bytes of the encrypted data as the first message authenticating code MAC1.

Step 508, return a message in response to the instruction INITIALIZE FOR CAPP LOAD to the terminal.

The message in response to the instruction INITIALIZE FOR CAPP LOAD is comprised of Data+sw1+sw2. In case of a successful execution of the instruction INITIALIZE FOR CAPP LOAD, both the status codes sw1 and sw2 in the response message are 9000 and thus data in Data field of the response message includes balance of CPU e-purse before the transaction, serial number of online transaction of CPU e-purse, version number of the key, algorithm ID, pseudo random number and MAC1; or in case of a failed execution, both the status codes sw1 and sw2 in the response message are not 9000 and there is not a DATA field.

Specifically in the embodiment, the message in response to the instruction INITIALIZE FOR CAPP LOAD is 00 00 00 00 00 01 02 03 01 02 03 04 00 01 B1 0A 90 00.

Step 509, receive a record updating instruction UPDATE RECORD sent by the terminal.

The record updating instruction UPDATE RECORD is used for updating data in a related record of the complex application specific file.

The complex application specific file is comprised of a file header and a file body. The file header includes a two-byte of FILE_ID, one-byte of FILE TYPE, two-byte of FILE SIZE, one-byte of AC1, one-byte of AC2 and two-byte of RFU, FILE TYPE 00 indicates a binary file. FILE TYPE 01 indicates a fix-sized record file, 02 indicates a changeable-sized record file, 03 indicates a recycle file and 05 indicates a key file.

Correspondingly, File Size for a binary file represents size of the file, File Size for a fix-sized record file refers to number and size of records, File Size for a changeable-sized record the refers to number and maximum size of records, File Size for a recycle file refers to number and size of records, and File Size for a key file to number and size of records. AC1 refers to a file reading privilege and AC2 to a file writing privilege. What is in the file body is data of the complex application specific file.

Specifically, the complex application specific file is a fix-sized record file, and thus FILE TYPE is 01 and FILE SIZE, referring to number and size of records, is 0A 10 and what is in the file body is empty.

Further, message of the instruction UPDATE RECORD is comprised of CLA+INS P1+P2+Lc Data, of which P1 and P2 are used for selecting a file and designating a record from the file as record for the complex application specific file and Lc is a value of 4 bytes plus size of data in Data field. Specifically, the instruction UPDATE RECORD is 80 DC 03 68 08 00 00 80 00, of which 00 refers to CLA, DC to INS, 03 to P1, 04 to P2, 08 to Lc and 00 00 80 00 to Data.

What is in Data field of the instruction UPDATE RECORD is new data to be written into the complex application specific file. Application special for each record of the complex application specific file may be defined by the card distributor, so be data in Data field.

Specifically, data in the self-defined Data field is a rate value herein, such as 80%, and it is written into a record for writing a rate value in the complex application specific file.

In case that the rate value is defined as 80%, data in the instruction UPDATE CAPP DATA CACHE may not be 80%, but 125 or 20%.

Or data in the instruction UPDATE CAPP DATA CACHE may not include a rate value, but generate a rate value by the transaction amount after a determination of the transaction amount included in the complex-loading initializing instruction by the CPU card, and the generated value is written into the complex application specific file.

Or data in the instruction UPDATE CAPP DATA CACHE includes a rate value and a premise thereof. Because the complex application specific file in the embodiment is a fix-sized record file, it is predetermined that each record of the complex application specific file includes a premise-based rate value. For example, in case that a purchase amount is bigger than RMB200 yuan and less than RMB300 yuan, the rate value is minus RMB20 yuan or 90%, which represents a deduction of RMB20 yuan or 10% discount upon reaching spending of RMB200 yuan; or in case that a purchase amount is bigger than RMB500 yuan and less than RMB600 yuan, the rate value is minus RMB100 yuan or 80%, which means a deduction RMB100 yuan or 20% discount upon reaching spending of RMB500 yuan. The premise pertained to each record of the complex application specific file is predetermined by a card distributor, and so is the rate value based on the premise.

Step 510, determine whether there is a short file identifier (SFI) field in the instruction UPDATE RECORD, if yes, Step 511 is executed; or if no, Step 512 is executed.

The determining whether there is a short file identifier (SFI) field in the instruction UPDATE RECORD is determining whether the high 5 bits of P2 in the instruction UPDATE RECORD are 0, if yes, there is an SFI field and the high 5 bits of P2 are value of SFI; or if no, there is not an SFI field.

In the embodiment, P2 of the instruction UPDATE RECORD is 68, it means that high 5 bits of P2 are 01101 and there is an SFI field.

Step 511, check whether there is a file under the current application, with a same SFI as that SFI in the instruction UPDATE RECORD, if no, Step 512 is executed; or if yes, Step 513 is executed.

Step 512, return a status code 0x6A82 to the terminal and end the complex-loading operation.

Step 513, take the file checked at Step 511 as the complex application specific file and retrieve a related record from the complex application specific file, according to a designated record number in the instruction UPDATE RECORD, if the record is not retrieved, Step 514 is executed; or it is retrieved, Step 515 is executed.

Specifically, P1 of the instruction UPDATE RECORD is 03, and thus the record numbering 03 in the complex application specific file is the record to be retrieved.

Step 514, return a status code 0x6A83 to the terminal and end the complex-loading operation.

Step 515, check whether size of Data field in the instruction UPDATE RECORD is larger than size of the record being retrieved at Step 513, if yes, Step 516 is executed; or if no, Step 517 is executed.

In the embodiment, the complex application specific file is a fix-sized record file and FILE SIZE in the complex application specific file refers to number and size of records, and therefore size of records in the complex application specific file is decided by value of FILE SIZE. Specifically, value of Lc of the instruction UPDATE RECORD is 08 and that of FILE SIZE is 0A 10, so size of Data field is not larger than that of the complex application specific file.

Step 516, return a status code 0x6A84 to the terminal and end the complex-loading operation.

Step 517, write data in Data field of the instruction UPDATE RECORD into the retrieved record to replace what is previously in it.

Specifically, the step is writing a rate value of 80% into the record and replacing what is previously in it. Because what is previously in the record is empty, the step is writing 00 00 80 00 in Data field of the instruction UPDATE RECORD, into Record 03 of the complex application specific file directly.

In case of a rate value of 125% in the instruction UPDATE RECORD, data being written into the record of the complex application specific file is 125% or in case of a rate value 20% in the instruction UPDATE RECORD, data being written into the pertained record of the complex application specific file is 20%.

Or data in the instruction UPDATE RECORD may not include a rate value itself, but generate a rate value by the transaction amount according to predetermined algorithm after determination of the transaction amount included in the complex loading initializing instruction by the CPU card, and the generated value is written into the complex application specific file.

For example, in case of a transaction amount of RMB800 yuan in the complex loading initializing instruction, less than a predetermined lower limit, such as RMB2000 yuan, a rate value of 95% or 105% or 5% is generated and written into the pertained record in the complex application specific file; or in case of a transaction amount of RMB5000 yuan in the complex loading initializing instruction, between a predetermined lower limit RMB2000 yuan and an upper limit RMB6000 yuan, a rate value of 80% or 125% or 20% is generated and written into the related record in the complex application specific file; or in case of a transaction amount of RMB8000 yuan in the complex loading initializing instruction, a rate value of 75% or 133% or 25% is generated and written into the designated record in the complex application specific file.

Or in case that each record of the complex application specific file records a rate value based on different premise, the rate value and related premise included in the instruction UPDATE RECORD is written into the pertained record, such as writing a rate value of minus RMB20 yuan or 90% and related premise of a purchase amount of between RMB200 yuan and RMB300 yuan, into the record; or writing a rate value of minus RMB100 yuan or 80% and related premise of a purchase amount of between RMB500 yuan and RMB600 yuan, into the record, and etc.

Step 518, return a message in response to the instruction UPDATE RECORD to the terminal.

The message in response to the instruction UPDATE RECORD is comprised of sw1 and sw2 and there is not a Data field. The response message is 9000 in case of a successful execution of the instruction UPDATE RECORD, or not 9000 in case of a failed execution of it.

Step 519, receive the complex loading instruction CREDIT FOR CAPP LOAD sent by the terminal, read and store data in Data field thereof.

The instruction CREDIT FOR CAPP LOAD is used for complex-loading of a transaction.

The message of the instruction CREDIT FOR CAPP LOAD is comprised of CLA+INS+P1+P2+Lc+Data+Le, of which data in Data field includes a transaction date, transaction time and a second message authenticating code MAC2.

The received instruction CREDIT FOR CAPP LOAD is 80 52 00 00 0B 07 DA 06 08 0A 14 2D 00 01 A1 0B 08, of which 80 refers to CLA, 52 to INS, 00 to P1, 0B to Lc, 07 DA 06 08 to the transaction date, 0A 14 2D to the transaction time, 00 01 A1 0B to MAC2 and 08 to Le.

Step 520, authenticate whether the second message authenticating code MAC2 is valid, if no, Step 521 is executed; or if yes, Step 522 is executed.

The authenticating whether MAC2 is valid includes steps of linking the transaction amount, transaction type id, terminal number, transaction date and time together, encrypting the linked data with the process key generated at Step 506 and comparing the first four bytes of the encrypted data to MAC2 in Data field of the instruction CREDIT FOR CAPP LOAD, if a match is not found, MAC2 is invalid; or if a match is found, MAC2 is valid.

Step 521, return a status code 0x9302 to the terminal and prompt an invalid MAC2. Step 522, add 1 to the serial number of online transaction of the e-purse, and the transaction amount to balance of the e-purse.

In case of a transaction amount of RMB1000 yuan and a balance of RMB0 yuan in the e-purse, the step is adding the transaction amount of RMB1000 yuan to balance of the e-purse to obtain a new balance of RMB1000 yuan.

Step 523, update transaction details of the e-purse, which specifically is linking the serial number of online transaction of the e-purse, transaction amount, transaction type id, terminal number, transaction date and time together to form a record for updating the standard transaction details.

Step 524, compute a transaction authenticating code (TAC).

The computing TAC includes steps of performing XOR operation on the right and left 8 bytes of the internal key DTK, linking balance of the after-transaction e-purse, serial number of online transaction of the e-purse before adding transaction amount, transaction type id, terminal umber, transaction date and time together, and encrypting the linked data with the result of the XOR operation to obtain a data TAC.

Step 525, return a message in response to the instruction CREDIT FOR CAPP LOAD to the terminal.

The message in response to the instruction CREDIT FOR CAPP LOAD is comprised of data+sw1+sw2. In case of a successful execution of the instruction, both the status codes sw1 and sw2 in the returned response message are 9000 and data in Data field of the response message is TAC, or the status codes sw1 and sw2 in the returned response message are not 9000 and there is not a Data field in the response message in case of a failed execution of the instruction.

The message in response to the instruction CREDIT FOR CAPP LOAD is 00 05 D2 BC 90 00.

Step 526, read and store data in a purchase initializing instruction INITIALIZE FOR PURCHASE.

The instruction INITIALIZE FOR PURCHASE is used for initializing a purchase and message of it is comprised of CLA+INS+P1+P2+Lc+Data+Le, of which data in Data field includes a key indexing number, a transaction amount and a terminal number.

The received instruction INITIALIZE FOR PURCHASE is 80 50 01 02 0B 02 00 00 00 C8 00 00 00 00 00 01 0F, of which 80 refers to CLA, 50 to INS, 01 to P1, 02 to P2, which is defined as an e-purse id, 0B to Lc, 02 to the key indexing number, 00 00 00 C8 to the transaction amount, 00 00 00 0 00 01 to the terminal umber and 0F to Le.

Step 527, check whether the CPU card supports the key indexing number included in the instruction INITIALIZE FOR PURCHASE, if no, Step 528 is executed; or if yes, Step 529 is executed.

Step 528, return a status code 0x9403 to the terminal and end the operation.

Step 529, compute the transaction amount included in the instruction INITIALIZE FOR PURCHASE and value in the related record of the complex application specific file according to predetermined algorithm, to obtain a new amount.

The predetermined algorithm includes multiplex, division, addition, subtraction and various combination of the four algorithms.

The value in record of the complex application specific file is a rate value, such as 80%, and in case of a purchase amount of RMB200 yuan, a new amount RMB160 yuan is computed by multiplying the purchase amount RMB200 yuan by the rate value 80% stored in the complex application specific file.

In case of a rate value of 125% being recorded in the complex application specific file, a new amount RMB160 yuan is obtained by dividing the purchase amount RMB200 yuan by the rate value 125% stored in the complex application specific file.

In case of a rate value of 20% being recorded in the complex application specific file, a new amount RMB160 yuan is computed by multiplying the purchase amount RMB200 yuan by the rate value of 20% to obtain RMB40 yuan and deducting RMB40 yuan from the purchase amount RMB200 yuan.

Or in case of a purchase amount RMB550 yuan, the new amount RMB450 yuan is computed by retrieving a rate value, such as minus RMB100 yuan, from a related record based on premise of the transaction amount of between RMB500 yuan and RMB600 yuan and adding the purchase amount RMB550 yuan to the rate value of minus RMB100 yuan.

Step 530, read balance of the e-purse and determine whether the new amount is bigger than the balance plus overdraft limit of the e-purse, if yes, Step 531 is executed; or if no, Step 532 is executed.

Step 531, return a status code 0x9401 to the terminal and end the operation.

Step 532, generate a pseudo random number and a process key.

The process key is used for purchase with a CPU e-purse or M1 e-purse, which is obtained by permission of DPK.

Step 533, send a message in response to the instruction INITIALIZE FOR PURCHASE to the terminal.

The response message is comprised of Data+sw1+sw2, and in case of a successful execution of the instruction, both the status codes sw1 and sw2 in the response message being returned to the terminal are 9000 and data in Data field of the response message includes a balance of e-purse, a serial number of offline transaction of CPU e-purse, an overdraft limit of CPU e-purse, a version number of the key, algorithm id and a pseudo random number; or in case of a failed execution, the response message being returned to the terminal includes only sw1 and sw2 and both of them are not 9000.

The message in response to the instruction INITIALIZE FOR PURCHASE being returned to the terminal is 00 00 4B 00 00 01 00 00 64 02 03 01 02 03 04 90 00.

Step 534, receive the purchase instruction DEBIT FOR PURCHASE sent by the terminal, read and store data in the instruction

The instruction DEBIT FOR PURCHASE is used for purchase.

The message of the instruction DEBIT FOR PURCHASE is also comprised of CLA+INS+P1+P2+Lc+Data+Le, and data in Data field includes a terminal transaction serial number, transaction date, transaction time and a third message authenticating code MAC3.

The received instruction DEBIT FOR PURCHASE is 80 54 01 00 0F 00 00 00 01 7D A0 06 09 0F 27 13 01 0A D1 0C 08, of which 80 refers to CLA, 54 to INS, 01 to P1, 00 to P2, 0F to Lc, 00 00 00 01 to the terminal transaction serial number, 7D A0 06 09 to the transaction date, 0F 27 13 to the transaction time, 010A D1 0C to MAC3 and 08 to Le.

Step 535, authenticate whether MAC3 included in the instruction DEBIT FOR PURCHASE is valid by the process key generated at Step 532, if no, Step 536 is executed; or if yes, Step 537 is executed.

The authenticating whether MAC3 included in the instruction DEBIT FOR PURCHASE is valid includes steps of linking the transaction amount, transaction type id, terminal number, transaction date and time together, encrypting the linked data with the process key generated at Step 532 and comparing the first four bytes of the encrypted data to MAC3 included in the instruction DEBIT FOR PURCHASE, if a match is found, MAC3 is valid; or if no, MAC3 is invalid.

Step 536, return a status code 0x9302 to the terminal and end the operation.

Step 537, add 1 to the serial number of offline transaction of the e-purse and deduct the new amount being obtained at Step 529 from the balance of the e-purse.

Step 538, update transaction details of the e-purse.

The transaction details to be updated include the transaction amount, transaction type id, terminal number, transaction date and time. Specifically, the CPU card links the transaction amount, transaction type id, terminal number, transaction date and time together to form a record for updating.

Step 539, generate a fourth message authenticating code MAC4 and compute a transaction authenticating code TAC.

The generating the fourth message authenticating code MAC4 includes steps of encrypting the transaction amount by the process key generated at Step 532 and taking the first four bytes of the encrypted data as the fourth message authenticating code MAC4.

The computing TAC by the result of the XOR operation includes steps of performing XOR operation on the right and left 8 bytes of DTK, linking the transaction amount, transaction type id, terminal number, terminal transaction serial number, transaction date and time together, encrypting the linked data with the result from the XOR operation and taking the first four bytes of the encrypted data as TAC.

Step 540, return a message in response to the instruction DEBIT FOR PURCHASE to the terminal and end the transaction.

The message in response to the instruction DEBIT FOR PURCHASE is comprised of data+sw1+sw2, and in case of a successful execution of the instruction, both the status codes sw1 and sw2 in the response message are 9000 and data in Data field are TAC and MAC4, or in case of a failed execution, the status codes sw1 and sw2 in the response message are not 9000 and there is not a Data field.

The message in response to the instruction DEBIT FOR PURCHASE is 01 0D B1 09 00 02 EA B1 90 00.

For example, the complex application specific file is a binary file, and thus the instruction for updating the complex application specific file, received by the CPU card is not a record updating instruction UPDATE RECORD, but an instruction UPDATE CAPP DATA CACHE, and following the reception of the instruction UPDATE CAPP DATA CACHE, the CPU card starts steps as follows.

Step 509′, receive the instruction UPDATE CAPP DATA CACHE for updating the complex application specific file sent by the terminal.

The instruction UPDATE CAPP DATA CACHE for updating the complex application specific file is used for updating data in the complex application specific file.

The message of the instruction UPDATE CAPP DATA CACHE is comprised of CLA+INS+P1+P2+Lc+Data. The instruction UPDATE CAPP DATA CACHE is 80 D6 92 B1 04 00 01 20 00, of which 80 refers to CLA, D6 to INS, 92 to P1, B1 to P2, 04 to Lc and 00 01 20 00 to Data.

Data in Data field of the instruction UPDATE CAPP DATA CACHE is new data to be written into the complex application specific file. Special application of the complex application specific file may be defined by a card distributor and so be the data in Data field. For example, the complex application specific file may be defined as a rate value file, and therefore data in Data field is a rate value, such as 120%.

In case that the complex application specific file is a binary file, FILE TYPE is 00, FILE SIZE refers to size of the file, for example 00 0B, and the file body is empty.

Step 510′, determine whether there is an SFI field in the received instruction UPDATE CAPP DATA CACHE, if yes, Step 511′ is executed; or if no, Step 512′ is executed.

The determining whether there is an SFI field in the instruction UPDATE CAPP DATA CACHE is determining whether the higher 3 bits of P1 in the instruction UPDATE CAPP DATA CACHE are 100, if yes, there is an SFI field and the lower five bits of P1 relates to the SFI field; or if no, there is not an SFI field.

In details, P1 of the instruction UPDATE CAPP DATA CACHE is 92, and thus the high 3 bits of P1 are 100 and there is an SFI field.

Step 511′, check whether there is a file under the current application of the CPU card with a same SFI as that SFI in the instruction UPDATE CAPP DATA CACHE, if no, Step 512′ is executed; or if yes, Step 513′ is executed.

Step 512′ return a status code 0x6A82 to the terminal and end the complex-loading transaction.

Step 513′, take the file checked at Step 511′ as the complex application specific file and check whether size of Data field of the instruction UPDATE CAPP DATA CACHE is larger than size of the complex application specific file, if yes, Step 514′ is executed; or if no, Step 515′ is executed.

Specifically the complex application specific file is a binary file, and thus size of it refers to value of FILE SIZE, and the determining step is determining whether value of Lc in the instruction UPDATE CAPP DATA CACHE is bigger than value of FILE SIZE in the complex application specific file. Specifically, value of Lc in the instruction UPDATE CAPP DATA CACHE is 04 and value of FILE SIZE is 00 0B, thus size of Data field is not larger than that of the complex application specific file.

Step 514′ return a status code 0x6A84 to the terminal and end the complex loading transaction.

Step 515′, write data, in Data field of the instruction UPDATE CAPP DATA CACHE, into the complex application specific file and replace what is previously in the complex application specific file.

Specifically, the step is writing a rate value of 120% into the complex application specific file and replace what is previously in it, and for an empty complex application specific file, the step is writing 00 01 20 00, in Data field of UPDATE CAPP DATA CACHE, into the complex application specific file.

Step 516′, return a message in response to the instruction UPDATE CAPP DATA CACHE to the terminal.

The message in response to the instruction UPDATE CAPP DATA CACHE is comprised of sw1+sw2 and there is not a Data field, and in case of a successful execution, the response message is 9000, or in case of a failed execution, the response message is not 9000.

The embodiment provides a method for purchase with an e-purse in a CPU card, which makes the complex-loading transaction safer and prevents the complex application specific file in the CPU card from being modified invalidly, and in the meanwhile the method simplifies the tier discount business by writing new data to the complex application specific file, and automatically deals with each spending, which is convenient for management and reduces cost on management.

The aforementioned are just preferred embodiments of the invention, not a limit to protection scope of the invention, and any modification or change easy to be performed by one skilled in the art within scope of the technology solution disclosed by the invention will be protected by the invention and the protection scope of the invention should be based on the claims. 

1. A method for operating an e-purse, comprising: entering into a contactless induction area of a terminal, being powered up and initialized by a CPU card; receiving an operation initializing instruction, which is a complex-loading initializing instruction or a purchase initializing instruction being sent by the terminal, by the CPU card; reading and storing data comprising a transaction amount, in the operation initializing instruction; in case that the operation initializing instruction is a complex-loading initializing instruction, performing a complex-loading initializing operation by the CPU card; receiving an instruction for updating a complex application specific file sent by the terminal and retrieving the complex application specific file by the CPU card; writing predetermined data into storage space of the complex application specific file and replacing what is previously in it by the CPU card; receiving the complex-loading instruction sent by the terminal, reading and storing data in the complex-loading instruction by the CPU card; computing transaction amount and data in the complex application specific file according to predetermined algorithm to obtain a new amount and adding the new amount to balance of the e-purse to obtain a new balance by the CPU card; in case that the operation initializing instruction is a purchase initializing instruction, computing the transaction amount and value in a related record of the complex application specific file according to predetermined algorithm to obtain a new amount by the CPU card; reading balance of the e-purse, determining whether the new amount is larger than balance of the e-purse plus the overdraft limit, if yes, returning a message of inadequate balance in the e-purse to the terminal and ending the operation by the CPU card; or if no, generating a pseudo random number and a process key, sending a message in response to the purchase initializing instruction to the terminal, receiving a purchase instruction sent by the terminal, reading and storing data in the purchase instruction, deducting the new amount from balance of the e-purse to obtain a newer amount and returning a message in response to the purchase instruction to the terminal by the CPU card.
 2. The method for operating an e-purse of claim 1, wherein data of the operation initializing instruction further comprises a key indexing number and a terminal number.
 3. The method for operating an e-purse of claim 1, wherein the predetermined algorithm comprises multiplex, dividing, addition, subtraction and various combination of the four algorithms.
 4. The method for operating an e-purse of claim 2, wherein in case that the operation initializing instruction is a purchase initializing instruction, before the computing transaction amount and value in the related record of the complex application specific file according to a predetermined algorithm, the method further comprises steps of: checking whether the key indexing umber is supported by the CPU card, if no, sending a message of unsupportable key indexing number to the terminal and ending the operation; or if yes, computing the transaction amount and value in the related record of the complex application specific file according to the predetermined algorithm.
 5. The method for operating an e-purse of claim 1, wherein in case that the operation initializing instruction is a purchase initializing instruction, data in the purchase initializing instruction comprises a terminal transaction number, transaction date, transaction time and a third message authenticating code.
 6. The method for operating an e-purse of claim 5, wherein in case that the operation initializing instruction is a purchase initializing instruction, before deducting the new amount from balance of the e-purse by the CPU card, the method further comprises steps of: authenticating whether the third message authenticating code is valid by the CPU card, if invalid, sending a message of invalid third message authenticating code to the terminal and ending the operation by the CPU card; if valid, adding 1 to the serial number of offline transaction of the e-purse and deducting the new amount from balance of the e-purse.
 7. The method for operating an e-purse of claim 1, wherein in case that the operation initializing instruction is a purchase initializing instruction, after deducting the new amount from balance of the e-purse to obtain a new balance by the CPU card, the method further comprises a step of: updating transaction details of the e-purse; and generating a fourth message authenticating code and a transaction authenticating code.
 8. The method for operating an e-purse of claim 1, wherein in case that the operation initializing instruction is a purchase initializing instruction, at a time of waiting for receiving an instruction sent by the terminal, the method comprises steps of: receiving complex-loading initializing instruction sent by the terminal, reading and storing data of the complex loading initializing instruction, and performing complex-loading initializing operation by the CPU card; receiving a record updating instruction sent by the terminal and updating data in the related record of the complex application specific file; receiving the complex-loading instruction sent by the terminal and performing the complex-loading operation.
 9. The method for operating an e-purse of claim 8, wherein in case that the operation initializing instruction is a purchase initializing instruction, the updating data in the related record of the complex application specific file further comprises steps of: retrieving the related record in the complex application specific file; determining whether size of data in the record updating instruction is larger than size of the retrieved record; if yes, sending a message of inadequate storage space for the record to the terminal and ending the operation by the CPU card; if no, updating data in the retrieved record by the CPU card.
 10. The method for operating an e-purse of claim 9, wherein in case that the operation initializing instruction is a purchase initializing instruction, the retrieving the related record in the complex application specific file comprises steps of: determining whether there is a short file identifier in the record updating instruction; if no, sending a message of unfound complex application specific file to the terminal and ending the operation; if yes, retrieving whether there is a file with a same short file identifier as the short file identifier, if no, sending a message of unfound complex application specific file to the terminal and ending the operation; or if yes, taking the retrieved file as the complex application specific file and retrieving a record according to record number designated in the record updating instruction, from the complex application specific file, if no being retrieved, sending a message of unfound related record to the terminal and ending the operation; if being retrieved, taking the retrieved record as the record to be updated.
 11. The method for operating an e-purse of claim 9, wherein in case that the operation initializing instruction is a purchase initializing instruction, the updating data in the retrieved record comprises steps of: writing data in the record updating instruction into the retrieved record and replacing what is previously in the retrieved record, or, determining the transaction amount included in the complex-loading initializing instruction according to a predetermined rule, generating data according to the determination result, writing the generated data into the retrieved record and replacing what is previously in the retrieved record.
 12. The method for operating an e-purse of claim 2, wherein in case that the operation initializing instruction is a complex-loading initializing instruction, the complex-loading initializing instruction comprises steps of: checking whether the key indexing number is supported by the CPU card; if no, sending a message of unsupportable key indexing number to the terminal and ending the operation by the CPU card; if yes, generating a pseudo random number and a process key and computing a first message authenticating code with the process key, and sending a message in response to the complex loading initializing instruction to the terminal by the CPU card.
 13. The method for operating an e-purse of claim 1, wherein in case that the operation initializing instruction is a complex-loading initializing instruction, the retrieving the complex application specific file comprises steps of: determining whether there is a short file identifier in the instruction for updating the complex application file, if no, taking the current file as the complex application specific file; if yes, checking whether there is a file under the current application with a same short file identifier as the short file identifier, if no, sending a message of unfound complex application specific file to the terminal and ending the operation; if yes, taking the checked file as the complex application specific file.
 14. The method for operating an e-purse of claim 1, wherein in case that the operation initializing instruction is a complex-loading initializing instruction, the predetermined data comprises: data included in the instruction for updating the complex application specific file, or data generated by the transaction amount included in the complex-loading initializing instruction.
 15. The method for operating an e-purse of claim 1, wherein in case that the operation initializing instruction is a complex loading initializing instruction, before writing the predetermined data into the storage space of the complex application specific file, the method further comprises steps of: determining whether size of the predetermined data is larger than size of the storage space of the complex application specific file, if yes, sending a message of inadequate storage space in the complex application specific file to the terminal and ending the operation; if no, writing the predetermined data into the storage space of the complex application specific file.
 16. The method for operating an e-purse of claim 1, wherein in case that the operation initialing instruction is a complex-loading initializing instruction, after writing the predetermined data into the storage space of the complex application specific file and replacing what is previously in the storage space, the method further comprises steps of: sending a message in response to the instruction for updating the complex application specific file to the terminal.
 17. The method for operating an e-purse of claim 1, wherein in case that the operation initializing instruction is a complex-loading initializing instruction, data in the complex loading instruction comprises transaction date, transaction time and a second message authenticating code; before computing the transaction amount and data in the complex application specific file according to predetermined algorithm, the method further comprises steps of: authenticating whether the second message authenticating code is valid; if invalid, returning a message of invalid second message authenticating code to the terminal and ending the operation; if valid, adding 1 to serial number of online transaction of the e-purse and computing the transaction amount and data in the complex application specific file according to predetermined algorithm.
 18. The method for operating an e-purse of claim 1, wherein in case that the operation initializing instruction is a complex-loading initializing instruction, after adding the new amount to balance of the e-purse to obtain a new balance, the method further comprises steps of: updating transaction details of the e-purse; computing a transaction authenticating code; returning a message in response to the complex loading instruction to the terminal.
 19. The method for operating an e-purse of claim 1, wherein in case that the operation initializing instruction is a complex loading initializing instruction, the instruction for updating the complex application specific file is a record updating instruction, and the retrieving the complex application specific file is retrieving the complex application specific file and a related record thereof.
 20. The method for operating an e-purse of claim 19, wherein in case that the operation initializing instruction is a complex-loading initializing instruction, the retrieving the complex application specific file and related record thereof is determining whether there is a short file identifier in the record updating instruction, if no, returning a message of unfound complex application specific file to the terminal and ending the operation; if yes, checking whether there is a file under the current application with a same short file identifier as the short file identifier, if no, returning a message of unfound complex application specific file to the terminal and ending the operation; if yes, taking the checked file as the complex application specific file and retrieving a record in the complex application specific file according to the record number designated in the record updating instruction; if no being retrieved, returning a message of unfound record for updating to the terminal and ending the operation; if being retrieved, taking the retrieved record as the record to be updated. 